<?php

/**
 * MVM_MALL 网上商店系统  商品对比
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-06-28 $
 * $Id: contrast.php  www.mvmmall.com$
 * ---------------------------------------------
*/

require_once './include/common.inc.php';
require_once MVMMALL_ROOT.'header.php'; 
$mm_brand   = $cache->get_cache('brand');//品牌
$id         = dhtmlchars($id);         
$sql        = "SELECT a.uid,a.goods_type,a.goods_name,a.goods_brand,a.goods_file1,a.goods_sale_price,a.goods_market_price,a.goods_category,a.goods_kg,a.upv,a.up_date,a.goods_advance,b.goods_id,b.*,c.id,c.att_name,c.att_type FROM `{$tablepre}goods_table` AS a LEFT JOIN `{$tablepre}att_value` AS b ON a.uid=b.goods_id LEFT JOIN `{$tablepre}attribute` AS c ON b.bute_id=c.id WHERE a.uid IN($id) AND a.upv='1' AND a.up_date<='$m_now_time'ORDER BY b.bute_id";
$result     = $db->query($sql);
while ($list=$db->fetch_array($result)){
   $list['url']                               = GetBaseUrl('product',$list['uid']);
   $goods_name[$list['uid']]['value']         = "<a href=\"$list[url]\" target=\"_blank\" title=\"$list[goods_name]\">$list[goods_name]</a>";
   $goods_photo[$list['uid']]['value']        = "<a href=\"$list[url]\" target=\"_blank\" title=\"$list[goods_name]\"><img src=\"$list[goods_file1]\" border=\"0\"></a>";
   $goods_sale_price[$list['uid']]['value']   = $list['goods_sale_price'];
   $goods_market_price[$list['uid']]['value'] = currency($list['goods_market_price']);
   $goods_sale_price[$list['uid']]['value']   = currency($list['goods_sale_price']);
   $goods_kg[$list['uid']]['value']           = $list['goods_kg'].'kg';
   $goods_brand[$list['uid']]['value']        = $mm_brand[$list['goods_brand']];
   $goods_advance[$list['uid']]['value']      = $list['goods_advance'];
   $goods_buy[$list['uid']]['value']          = "<a href=\"javascript:put_flow($list[uid],'C')\" >$lang[buy]</a> |  <a href=\"javascript:put_flow($list[uid],'S')\" >$lang[wish]</a>";
   $arr[$list['att_id']]['name']              = $list['att_name'];
   $arr[$list['att_id']]['value']             = $list['att_value'];
   $arr[$list['att_id']]['price']             = $list['att_price'];
   $arr[$list['att_id']]['att_type']          = $list['att_type'];
   $arr[$list['att_id']]['goods_id']          = $list['uid'];                                                  
   $attr_list = array();
   $query = $db->query("SELECT att_name,id,type_id FROM `{$tablepre}attribute` WHERE type_id='$list[goods_type]' ORDER BY id");
   while ($rs = $db->fetch_array($query)){
       $attr_list[$rs['id']] = $rs['att_name'];
   }
}
$goods_list[0]['title'] = $lang['buy_name'];
$goods_list[0]['value'] = $goods_name;
$goods_list[1]['title'] = $lang['buy_pic'];
$goods_list[1]['value'] = $goods_photo;
$goods_list[2]['title'] = $lang['marketprice'];
$goods_list[2]['value'] = $goods_market_price;
$goods_list[3]['title'] = $lang['buy_price'];
$goods_list[3]['value'] = $goods_sale_price;
$goods_list[4]['title'] = $lang['kg'];
$goods_list[4]['value'] = $goods_kg;
$goods_list[5]['title'] = $lang['brand'];
$goods_list[5]['value'] = $goods_brand;
$i                      = count($goods_list);

foreach ($attr_list as $val){
	foreach ($arr as $key=>$rs){
		if ($rs['name']==$val && $rs['att_type']==0){
			$row[]['value'] = $rs['value'];
		}elseif ($rs['name']==$val && $rs['att_type']==1){
			$rs['goods_id'] == $row[$rs['goods_id']]['goods_id'] && $row[$rs['goods_id']]['value'] =' '.$rs['value'].currency($rs['price']);
			$row[$rs['goods_id']]['value'].=' '.$rs['value'].currency($rs['price']);
		}
	}
	$goods_list[$i]['title'] = $val;
	$goods_list[$i]['value'] = $row;
	unset($row);
	++$i;
}
$goods_list[$i]['title']   = $lang['goods_advance'];
$goods_list[$i]['value']   = $goods_advance;
$goods_list[$i+1]['title'] = '---';
$goods_list[$i+1]['value'] = $goods_buy;
require_once template('contrast');
footer();